package com.szt.sy.service.system.dicttype;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.szt.sy.entity.system.DictType;
import com.szt.sy.mapper.system.DictTypeMapper;

/**
 * @author wwy
 *
 *         <p>
 *         说明：数据字典类型 服务<br/>
 *         创建时间：2018-01-15
 *         </p>
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class DictTypeService extends ServiceImpl<DictTypeMapper, DictType> {
	
	/**
	 * 列表
	 * 
	 * @param page
	 * @
	 */
	public Page<DictType> list(Page<DictType> page, Map<String, Object> map) {
		page.setRecords(baseMapper.dataList(page, map));
		return page;
	}
	
	/**
	 * 列表(全部)
	 * 
	 * @param pd
	 * @
	 */
	public List<DictType> listAll(Map<String, Object> map) {
		return baseMapper.dataList(map);
	}
	
	/***
	 * 获取字典类型-树形数据
	 * 
	 * @param pid
	 * @return
	 */
	public List<DictType> treeList(Long pid) {
		if (pid == null) {
			return null;
		}
		List<DictType> nodes = baseMapper.selectList(new EntityWrapper<DictType>().eq("pid", pid));
		if (nodes == null || nodes.isEmpty()) {
			return nodes;
		}
		for (DictType node : nodes) {
			node.setNodes(treeList(node.getId()));
		}
		return nodes;
	}
	
}
